package com.example.myapplication.flutter;

import android.app.Activity;

import com.orhanobut.logger.Logger;

import io.flutter.embedding.android.FlutterView;
import io.flutter.embedding.engine.FlutterEngine;
import io.flutter.plugin.common.BasicMessageChannel;
import io.flutter.plugin.common.StringCodec;

//这里支持的数据类型为String。
public class BasicMessageChannelPlugin implements BasicMessageChannel.MessageHandler<String> {
    private BasicMessageChannel<String> messageChannel;

    public BasicMessageChannelPlugin( FlutterEngine flutterEngine) {
        this.messageChannel = new BasicMessageChannel<String>(flutterEngine.getDartExecutor(),
                "BasicMessageChannelPlugin", StringCodec.INSTANCE);
        messageChannel.setMessageHandler(this);
    }


    @Override
    public void onMessage(String s, BasicMessageChannel.Reply<String> reply) {
        reply.reply("BasicMessageChannelPlugin收到：" + s);
        Logger.d("===onMessage: 来自flutter传递过来的数据="+s);

    }

    void send(String str, BasicMessageChannel.Reply<String> reply) {
        messageChannel.send(str, reply);
    }
}
